package com.wiiss.ams;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.wiiss.ams.cron.Scheduler;
import com.wiiss.ams.util.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.nio.file.Paths;

@SpringBootApplication
public class AmsApplication {

    private static final Logger log = LoggerFactory.getLogger(AmsApplication.class);

    public static void main(String[] args) {
// 默认加载第一个.conf文件, 文件中是jsonObject格式UTF-8文本
        for (File file : FileUtil.ls(Paths.get("").toAbsolutePath().toString())) {
            if (file.getAbsolutePath().endsWith(".conf")) {
                Cache.set(JSONUtil.parseObj(FileUtil.readUtf8String(file)));
                break;
            }
        }

        // 启动定时器
        try {
            Scheduler.launch();
        } catch (Exception e) {
            log.error("Scheduler", e);
        }

        SpringApplication.run(AmsApplication.class, args);
    }

}
